<?php namespace App\Models\Cxhshop;

use App\Models\Base\CxhshopBase;
use Illuminate\Support\Facades\DB;
class News extends CxhshopBase { 
    public $timestamps = false;//这里表示的是不添加时间
    // protected $connection='jmft_cxh';
    protected $table = 'ims_cxh_news';

   
    //获取全部类型
    public function getnews($type,$page,$number){
        $newarr = array();
        $filed = ['id','title','img','created_at','updated_at','type','click'];
        $query = self::query();
        $date =$query->where('type','=',$type)->forPage($page,$number)->get($filed);
        $data = DB::connection('jmft_cxh')->table('ims_cxh_news_banner')->where('type','=',$type)->get();
        $newarr['news'] =  $date;
        $newarr['banner'] = $data;
        if(!empty($newarr['news'])){
            return $newarr;
        }else{
            return false;
        }
        
    }
    public function getnewsdetail($newsid){
        $field = ['content','click'];
        $query = self::query();
        $data = $query->where('id','=',$newsid)->first($field);
        if(!empty($data)){
            $param =['click'=>$data->click+1];
            $query->where('id','=',$newsid)->update($param);
            return $data;
        }else{
            return false;
        }
    }

   

}